package com.sc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sc.mapper.InformationMapper;
import com.sc.pojo.Information;
import com.sc.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 陈远坤
 */
@Service
@Transactional
public class InformationServiceImpl implements InformationService {
    @Autowired
    InformationMapper mapper;
    @Override
    public void addInformation(Information ins) {
        mapper.insert(ins);
    }

    @Override
    public PageInfo<Information> selectAllInfs(Integer id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Information> list = mapper.selectAllInfs(id);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Information> selectAllInfsByLikes(Integer id, Integer pageNum, Integer pageSize, String likes) {
        PageHelper.startPage(pageNum,pageSize);
        List<Information> list = mapper.selectAllInfsByLikes(id,likes);
        return new PageInfo<>(list);
    }

    @Override
    public void updateAcceptState(Integer id) {
        mapper.updateAcceptById(id);
    }

    @Override
    public void deleteById(Integer id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<Information> selectAllLjInfos(Integer id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Information> list = mapper.selectAllLjInfos(id);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Information> selectAllLjInfosByLikes(Integer id, Integer pageNum, Integer pageSize, String likes) {
        PageHelper.startPage(pageNum,pageSize);
        List<Information> list = mapper.selectAllLjInfosByLikes(id,likes);
        return new PageInfo<>(list);
    }

    @Override
    public void updateAcceptStateinLjx(Integer id) {
        mapper.updateAcceptByIdInLjx(id);
    }

    @Override
    public void updateAcceptStateByYidu(Integer id) {
        mapper.updateAcceptStateByYidu(id);
    }

    @Override
    public PageInfo<Information> selectAllInfsByMy(Integer id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Information> list = mapper.selectAllInfsByMy(id);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Information> selectAllInfsByMyByLikes(Integer id, Integer pageNum, Integer pageSize, String likes) {
        PageHelper.startPage(pageNum,pageSize);
        List<Information> list = mapper.selectAllInfsByMyByLikes(id,likes);
        return new PageInfo<>(list);
    }

    @Override
    public void updateSend(Integer id) {
        mapper.updateSend(id);
    }
}
